<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
    <%
      String basePath = request.getScheme()+"://"+request.getServerName()+":"
              +request.getServerPort()+request.getContextPath()+"/";
    %>
    <base href="<%=basePath%>">
    <script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
    <script type="text/javascript">
      $(function(){
        submitForm();
      });
      function submitForm(){
        var data = $("#form1").serialize();
        $.ajax({
          type:"POST",
          url:"findPosition.action",
          data:data,
          success:function(arr){
            var str = "";
            for (var i =0;i<arr.length;i++){
              str+=' <tr>\n' +
                      '<td>'+arr[i].pname+'</td>\n' +
                      '<td>'+arr[i].cname+'</td>\n' +
                      '<td>'+arr[i].minSal+'-'+arr[i].maxSal+'</td>\n' +
                      '<td>'+arr[i].location+'</td>\n' +
                      '<td>'+arr[i].releaseDate+'</td>\n' +
                      '<td>' +
                      '<a href="javascript:void(0)" onclick="deletePosition('+arr[i].pid+')">删除</a>' +
                      '&nbsp;&nbsp;<a href="findPositionById.action?pid='+arr[i].pid+'">修改</a>' +
                      '</td>\n' +
                      '</tr>';
            }
            $("#tbody1").html(str);
          }
        });
      }

      function deletePosition(pid){
        var flag =  window.confirm("您确认要删除该岗位吗？")
        if(flag){
          $.ajax({
            type:"GET",
            url:"deletePosition.action",
            data:{"pid":pid},
            success:function(result){
              if(result=='ok'){
                //刷新页面
                alert("删除成功");
                window.location.reload();
              }else{
                alert("删除失败");
              }
            }
          });
        }
      }
    </script>
  </head>
  <body>
  <a href="positionAdd.jsp">新增岗位</a>&nbsp;&nbsp;&nbsp;&nbsp;
  <a href="page/companyAdd.jsp">新增公司</a>&nbsp;&nbsp;&nbsp;&nbsp;
  <a href="page/companyList.jsp">公司列表</a>&nbsp;&nbsp;&nbsp;&nbsp;
  <hr>
  <form id="form1">
    <table>
      <tr>
        <td>职位名称:<input type="text" name="pname" id="pname"> </td>
        <td>薪资范围：<input type="text" name="minSal" id="minSal">---<input type="text" name="maxSal" id="maxSal"> </td>
        <td><input type="button" value="查询" onclick="submitForm()"> </td>
      </tr>
    </table>
  </form>
  <hr>

  <table border="1" width="50%">
    <tr>
      <th>职位名称</th>
      <th>公司名称</th>
      <th>职位月薪</th>
      <th>工作地点</th>
      <th>发布日期</th>
      <th>操作</th>
    </tr>
    <tbody id="tbody1">

    </tbody>
  </table>
  </body>
</html>
